package com.zx.server.service.impl;


import com.zx.server.dao.ContactDao;
import com.zx.server.entity.ContactEntity;
import com.zx.server.entity.IdentityEntity;
import com.zx.server.service.ContactService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther: zhangxin
 * @Description:
 */
@Service
public class ContactServiceImpl implements ContactService {

    private  static final String INPUT="identity_queueC";

    @Autowired
    public ContactDao contactDao;

    @Autowired
    ContactService contactService;

    @Override
    public int addContact(ContactEntity contactEntity) {
        int num = contactDao.addContact(contactEntity);
        return num;
    }

    @Override
    public int updateContact(ContactEntity contactEntity) {

        int num = contactDao.updateContact(contactEntity);
        return num;
    }

    @Override
    public List<ContactEntity> getContactList(List<Integer> ids) {
        return contactDao.getContactList(ids);
    }

    @RabbitListener(queues=INPUT)
    @RabbitHandler
    public void receive(IdentityEntity identity) {

        System.out.println("......................."+identity.toString()+"................");
        ContactEntity contactEntity = new ContactEntity();
        contactEntity.setName(identity.getRealName());
        contactEntity.setId(identity.getId());
        contactService.updateContact(contactEntity);

    }


}
